package com.yeban.base.day04;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/9/28
 */
// 冒泡排序
public class SortTest01 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

//        System.out.print("请输入需要排序数组的个数n：");
//        int n = sc.nextInt();
//        System.out.print("请输入需要排序的数组：");
//        int[] arr = new int[n];
//        for (int i = 0; i < n; i++) {
//            arr[i] = sc.nextInt();
//        }
        int[] arr = {3,4,5,2,11,8,1};
        int n = arr.length;

        // 冒泡排序
        int count = 0;
        //趟数
        for (int i = 0; i < n - 1; i++) {
            //次数/趟
            for (int j = 0; j < n - i - 1; j++) {
                if(arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }

            count ++;
        }

        long end = System.currentTimeMillis();	//结束时间记录
        System.out.println("一共进行了：" + count + "趟！");

        System.out.println(Arrays.toString(arr));
        System.out.println();
    }
}
